package cn.repository;

import cn.entity.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

/**
 * @author m on 2023/1/27
 * Description:
 */
public interface UserRepository extends JpaRepository<User, UUID> {

    User findUserByUserNameAndPassword(String userName,String password);
    Integer countByUserName(String name);
    User findUserByUserName(String name);
    //查询所有用户
    Integer countAllBy();

    //查找所有用户
    List<User> findAllByOrderByUpdateTimeDesc();
    //分页查询用户
    List<User> findAllByOrderByUpdateTimeDesc(Pageable pageable);
    //查询申请认证
    List<User> findUsersByApplyOrderByUpdateTimeDesc(boolean is);


    //模糊查询用户名/昵称/email/电话号码/
    @Query("select u from User u where u.userName like CONCAT('%',:kw,'%') or u.nickName " +
            "like CONCAT('%',:kw,'%') or u.email like CONCAT('%',:kw,'%') or u.phone like CONCAT('%',:kw,'%')")
    List<User> findByQuery(@Param("kw") String kw);


    List<UserProjection> findUsersByUserName(String userName);
}
